﻿@using Telerik.Web.Mvc.UI;
@using System.Linq;
@{
    var gridPageSize = EngineContext.Current.Resolve<SmartStore.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    ViewBag.Title = T("Admin.Catalog.ProductTags").Text;
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "product-tags-form" }))
{
    <div class="section-header">
        <div class="title">
            <i class="fa fa-tags"></i>
            <span>@T("Admin.Catalog.ProductTags")</span>
        </div>
    </div>

    <script>
        function onRowDataBound(e) {
	        if (!e.dataItem.Published) {
		        $(e.row).find('td').wrapInner('<span class="muted" />');
	        }
        }
    </script>

    <div>
		@(Html.Telerik().Grid<ProductTagModel>()
            .Name("product-tags-grid")
            .DataKeys(x =>
            {
                x.Add(y => y.Id);
            })
            .Columns(columns =>
            {
                columns.Bound(x => x.Name);
                columns.Bound(x => x.ProductCount)
                    .Centered()
                    .Width(300);
                columns.Bound(x => x.Published)
                    .ClientTemplate(Html.SymbolForBool("Published"))
                    .Centered()
                    .Width(300);
                columns.Command(commands =>
                {
                    commands.Custom("edit-product-tag").Text(T("Common.Edit"));
                    commands.Delete().Localize(T);
                })
                .Width(200)
                .HtmlAttributes(new { align = "right", @class = "omega" });
            })
            .DataBinding(dataBinding =>
            {
                dataBinding.Ajax()
                    .Select("ProductTags", "Product")
                    .Delete("ProductTagDelete", "Product");
            })
            .ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
            .Filterable()
            .Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
            .PreserveGridState()
            .EnableCustomBinding(true))

		<input type="submit" id="btnRefresh" name="btnRefresh" style="display: none" />
	</div>
}

<script>
	$(function() {
		$('#btnRefresh').click(function () {
			$('#product-tags-grid').data('tGrid').ajaxRequest();
			return false;
		});

		$('#product-tags-grid').on('click', '.t-grid-edit-product-tag', function (e) {
			e.preventDefault();
			var grid = $('#product-tags-grid').data('tGrid');
			var tr = $(this).closest('tr');
			var id = grid.dataItem(tr).Id;
			var href = "@Url.Content("~/Admin/Product/EditProductTag/")" + id + "?btnId=btnRefresh&formId=product-tags-form";

			openPopup(href);
			return false;
		});
	});
</script>